/**
 * <p>Title: ServiceZMCS04.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-1-12 下午05:28:19  张志芳  Create
 *</pre>
 */
package com.baosight.sczx.zm.cs.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ef.ui.tree.TreeConstants;
import com.baosight.iplat4j.ef.ui.tree.TreeService;
import com.baosight.iplat4j.ep.QueryMap;
import com.baosight.sczx.common.zm.cInterface.cs.Mine;
import com.baosight.sczx.common.zm.cInterface.cs.ProductionSystem;
import com.baosight.sczx.common.zm.cInterface.cs.ProductionUnits;
import com.baosight.sczx.common.zm.cInterface.cs.Variable;
import com.baosight.sczx.common.zm.cInterface.cs.VariableGroup;

/**
 * 矿井模型：构造树
 * <p>Title: ServiceZMCS04.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-1-12 下午05:28:19  张志芳  Create
 *</pre>
 */
public class ServiceZMCS40 extends TreeService {

	/**
	 * 查询根节点下的数据
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS04</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-24上午11:03:09 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public EiInfo query(EiInfo inInfo) {
		QueryMap queryInfo = QueryMap.getQueryMap(inInfo);
		String _node = (String) queryInfo.get(TreeConstants.TREE_NODE);
		String level = (String) queryInfo.get("level");
		List _list = new ArrayList();
		
		if (_node == null) {
			_node = "$";
		}
		if ("$".equals(_node)) {
			_list = this.getTopNodes();//得到根节点
		} else {
			_list = this.getChildNodes(_node, level);
		}

		EiInfo outInfo = new EiInfo();
		EiBlock block = outInfo.addBlock(_node);
		block.setBlockMeta(initMetaData());
		block.setRows(_list);
		return outInfo;
	}
	
	/**构造矿井信息树节点的孩子节点
	 * <p>Function: getChildNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS04</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-12下午05:28:19 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List getChildNodes(String _arg, String level) {
		String parentLabel = _arg;
		Map<String, String> _argMap = new HashMap<String, String>();
		_argMap.put(TreeConstants.TREE_NODE, parentLabel);
		int _int = level == null ? 0 : Integer.parseInt(level);
		
		switch(_int) {
			case 0:
				//矿井
				return Mine.getMineTree(_argMap, true);
			case 1:
				//生产系统
				return ProductionSystem.getProductionSystemTree(_argMap, true);
			case 2:
				//生产单元
				return ProductionUnits.getProductionUnitsTree(_argMap, true);
			case 3:
				//变量组 & 变量
				List _list = VariableGroup.getVariableGroupTree(_argMap, true);
				_list.addAll(Variable.getVariableTree(_argMap, true));
				return _list;
			case 4:
				//变量
				return Variable.getVariableTree(_argMap, true);
			default:
				return new ArrayList();
		}
		
	}

	/**根节点构造
	 * <p>Function: getTopNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS04</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-12下午05:28:19 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public List getTopNodes() {
		List topNodes = new ArrayList();
		Map map = new HashMap();
		map.put("display", "矿井建模");
		map.put("value", "ROOT");
		map.put("level", "0");
		map.put("isLeaf", "0");
		map.put("image", "root.png");
		topNodes.add(map);
		return topNodes;
	}
	
	/**
	 * 父类的方法
	 * <p>Function: getChildNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS40</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-1上午01:56:07 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public List getChildNodes(String arg0) {
		return null;
	}
	
	/**数据列定义
	 * <p>Function: initMetaData</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS04</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-12下午05:28:19 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiBlockMeta initMetaData() {
		EiBlockMeta eiMetadata = new EiBlockMeta();

		EiColumn eiColumn = new EiColumn("display");
		eiColumn.setDescName("显示名称");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("value");
		eiColumn.setDescName("实际值");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("level");
		eiColumn.setDescName("树级别");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("isLeaf");
		eiColumn.setDescName("是否叶子节点");
		eiColumn.setType(EiConstant.COLUMN_TYPE_NUMBER);
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("image");
		eiColumn.setDescName("图片");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		return eiMetadata;
	}
}
